program colortable;
{控制台打印各种前景色和背景色的组合。}
{$mode fpc}
const
	escseq: string = #&33'[';
var
	i: byte;
procedure resetcolor;
begin
	write(escseq + '0m');
end;
procedure color(t, b: byte);
var
	cs: string[32];
	ecs: string[2];
begin
	if t > $F then t := $F;
	if t > $7 then begin
		str((30 + t - $8):2, ecs);
		cs := '1;' + ecs; 
	end else begin 
		str((30 + t):2, cs);
	end;
	if b <= $7 then begin
		str((40 + b):2, ecs);
		cs := cs + ';' + ecs;
	end;
	write(escseq, cs, 'm');
end;
procedure writerow(b: byte);
var
	i: byte;
begin
	for i := $0 to $F do begin
		color(i, b);
		write('X');
	end;
	resetcolor;
	writeln;	
end;
begin
	resetcolor;
	writeln('    COLOR TABLE ');
	writeln('  0123456789ABCDEF');
	write('D ');
	writerow($FF);
	for i := $0 to $7 do begin
		resetcolor;
		write(hexstr(i, 1), ' ');
		writerow(i);
	end;
	resetcolor;
end.